<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>修改数组</title>
    <script src="/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <h2>修改数组类型的数据</h2>
      <p>{{hobbys}}</p>
      <button @click="updataHobby">修改</button>
    </div>
    <script>
      Vue.config.productionTip = false;
      const vm = new Vue({
        el: "#app",
        data() {
          return {
            hobbys: ["抽烟", "喝酒", "烫头"],
          };
        },
        methods: {
          updataHobby() {
            /* js的限制,无法检测数组中某个值的变化,所以直接修改数组视图不会更新 */
            /* Vue 将被侦听的数组的变更方法进行了包裹，所以它们也将会触发视图更新 */
            this.hobbys.push("蹦迪");
          },
        },
      });
    </script>
  </body>
</html>
